﻿<%@ Page Language="C#" MasterPageFile="~/ExampleMaster.Master" AutoEventWireup="true"
    CodeBehind="AnonSelect.aspx.cs" Inherits="Web.Samples.AnonSelect1" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleZone" runat="server">
    Anonymous Select with LINQ
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="IntroTextZone" runat="server">
    Selecting using Anonymous objects allows for customization of the objects coming
    back, this can be very useful in bringing back sets of aggregated data, or to trim
    results to making binding easier. The limitation is that while runtime binding of
    properties is possible, performing operations on databound events becomes complex
    as the compiler cannot guarentee what properties the anonymous object holds.
    <p>
    </p>
    The following examples extract define a set of anonymous objects with two properties
    Display and Value defined accordingly.
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="QueryExpressZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">var</span> query = <span
        style="color: rgb(0,0,255)">from</span> sp <span style="color: rgb(0,0,255)">in</span> <span
            style="color: rgb(43,145,175)">StateProvince</span>.GetStateProvinces()
                        <span style="color: rgb(0,0,255)">select</span> <span style="color: rgb(0,0,255)">new
                        </span>                        {
                            Display = sp.Name + <span style="color: rgb(163,21,21)">" - "</span> + sp.Addresses.Count.ToString(),
                            Value = sp.TerritoryID
                        };

            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(0,0,255)">var</span> o <span
                style="color: rgb(0,0,255)">in</span> query)
                <span style="color: rgb(0,0,255)">this</span>.litExpressionResults.Text += <span
                    style="color: rgb(0,0,255)">string</span>.Format(<span style="color: rgb(163,21,21)">"Value:
                        {0} - Display: {1}&lt;br /&gt;\n"</span>, o.Value, o.Display);</pre>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="QueryResultsZone" runat="server">
    <asp:Literal ID="litExpressionResults" runat="server" />
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ImperativeZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">var</span> query = <span
        style="color: rgb(43,145,175)">StateProvince</span>.GetStateProvinces().Select(sp =&gt;
                <span style="color: rgb(0,0,255)">new</span> { Display = sp.Name + <span style="color: rgb(163,21,21)">"
                    - "</span> + sp.Addresses.Count.ToString(), Value = sp.TerritoryID });

            <span style="color: rgb(0,0,255)">foreach</span> (<span style="color: rgb(0,0,255)">var</span> o <span
                style="color: rgb(0,0,255)">in</span> query)
                <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += <span
                    style="color: rgb(0,0,255)">string</span>.Format(<span style="color: rgb(163,21,21)">"Value:
                        {0} - Display: {1}&lt;br /&gt;\n"</span>, o.Value, o.Display);</pre>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ImperativeResultsZone" runat="server">
    <asp:Literal ID="litImperativeResults" runat="server" />
</asp:Content>
